<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let array = [12,43,431,4321,879,431,1,77,77,99,100,];
        function sort(array){
            sortChild(array,0,array.length-1);
            // document.write(array);
            console.log(array.toString());
        }
        function sortChild(arr,l,r){
            if(l >= r) return;
            let left = l-1,right = r+1,i = l;
            let ran = Math.floor(Math.random()*(r-l+1));
            let k = arr[ran+l];
            // 数组分三块
            while(i < right){
                if(arr[i] < k) swap(arr,++left,i++);
                else if(arr[i] > k) swap(arr,--right,i);
                else ++i;
            }
            sortChild(arr,l,left);
            sortChild(arr,right,r);
        }
        function  swap(arr,i,j){
            let t = array[i];
            arr[i] = arr[j];
            arr[j] = t;
        }
        sort(array);
    </script>
</body>
</html>